#!/usr/bin/env python
# coding=UTF-8
'''
 * @Author       : z417
 * @Date         : 2020-03-15 10:26:23
 * @LastEditors: z417
 * @LastEditTime: 2020-03-15 10:42:49
 * @FilePath     : \\python/autoDemo/common/log.py
 * @Description  : file desc
'''

import logging
import logging.config
import os
import functools


def singleton(cls):
    """
    用于单例设计模式
    """
    instances = {}
    @functools.wraps(cls)
    def _wrapper(*args, **kw):
        if cls not in instances:
            instances[cls] = cls(*args, **kw)
        return instances[cls]
    return _wrapper


@singleton
class Log():
    def __init__(self, name='root'):
        self.__conf__ = os.path.join(os.path.dirname(
            os.path.dirname(__file__)), 'conf', 'log.ini')
        logging.config.fileConfig(self.__conf__)
        self.__logger__ = logging.getLogger(name)

    def reset(self, name='root'):
        self.__conf__ = os.path.join(os.path.dirname(
            os.path.dirname(__file__)), 'conf', 'log.ini')
        logging.config.fileConfig(self.__conf__)
        self.__logger__ = logging.getLogger(name)
        return self

    @property
    def get_logger(self):
        return self.__logger__


L = Log(__name__).get_logger

if __name__ == '__main__':
    L.info('this is info msg')
